Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending @uni19's work on support dynamic shape input and scale_factor in interpolate layer #295

Merged
merged 5 commits into from
Jan 28, 2021

Conversation

narendasan
Copy link
Collaborator

Description

This PR includes the changes in #258, does some refactoring of the test suite for interpolate and should expand coverage of the interpolate converter for the two variants of each of the currently supported resize functions (self, and vec). It should mean that we support interpolate for nearest and linear variants for all cases except when users use a type of linear upsampling, use scale factor for setting the size and set align_corners to true. It seems like @uni19 found that TensorRT and PyTorch have different behavior in this case. I will check with the TRT team to see if they have observed this. Hopefully it is not a massive issue as PyTorch since 1.5 has switched to align_corners being false by default. As a stop gap this PR extends the interpolate plugin to handle this case, however it can only do so for static TRT engines. Currently the build time dimension calculation can only be done with ints where as scale factors for PyTorch are floats. Therefore in the case of dynamic engine for a model using [Bi/Tri]Linear interpolate with scale factor and align_corners=True, TRTorch will error out. Hopefully this is niche enough of a use case to not cause issues until we get a response from TensorRT.

Fixes #290

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes

uni19 and others added 5 commits December 20, 2020 21:13
suite

This commit adds onto the work done by @uni19 and adds support for the
two variants of upsample ops. It also radically simplifies the tests for
this component.

Known issues: Right now both for scales and scale factors align corners
being true causes errors

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
… edge case

This commit adds support in some cases for the edge case when handling
torch.nn.functional.interpolate where the user is doing some form of
linear upsampling and uses scale factor to calculate the new tensor size
at runtime and they set align corners to true (as of PyTorch 1.5 this is
no longer the default behavior). This commit adds support for this
case when users chose to construct static input size engines via the
interpolate plugin which will run the function from ATen on CPU.

In the case of dynamic input shapes with these 3 conditions the
compilation will terminate with an error. The ultimate solution will be
to find the root cause of the descripancy between PyTorch and TensorRT.
Barring that we will need to use the dimension calculation primatives for
TensorRT plugins. However, there is a limitation where static values in
the computation cannot be floats which PyTorch scale factors are. Therefore
it doesn't seem possible currently to support this usecase.

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
@narendasan narendasan requested a review from peri044 January 27, 2021 09:35
@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: tests Issues re: Tests labels Jan 27, 2021
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code conforms to C++ style guidelines

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified testcases on my local with TRT 7.2.2.3

@narendasan narendasan merged commit 8fb390d into master Jan 28, 2021
@narendasan narendasan deleted the dynamic_interpolation branch January 28, 2021 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

↔ [Converter] Add support for aten::upsample_nearest2d.vec in TRTorch
3 participants